package com.le.tester.leetcode;

/**
 * 描述：
 */
public class StrPalindrome {
    public boolean isPalindrome(String s) {
        s = s.replaceAll("[^a-zA-Z0-9]", "");
        if (s.trim().length() == 0 || s.length() == 1) {
            return true;
        }
        String lowerStr = s.toLowerCase();
        int length = lowerStr.length();
        int i = length / 2;
        String fontStr = lowerStr.substring(0, i);
        //偶数
        if (length % 2 == 0) {
            String endStr = lowerStr.substring(i, length);
            StringBuilder reverseEndStr = new StringBuilder(endStr).reverse();
            return fontStr.equals(String.valueOf(reverseEndStr));
            //return lowerStr.charAt(i) == lowerStr.charAt(i - 1);
        } else {
            //奇数
            String endStr = lowerStr.substring(i + 1, length);
            StringBuilder reverseEndStr = new StringBuilder(endStr).reverse();
            return fontStr.equals(String.valueOf(reverseEndStr));
            //return lowerStr.charAt(i - 1) == lowerStr.charAt(i + 1);
        }
    }

    public static void main(String[] args) {
        System.out.println(new StrPalindrome().isPalindrome("Suuv,5?tt?5,vYYS"));
    }
}
